<?php

namespace Home\Controller;

class CommissionController extends BaseMallController {

    function _initialize() {
        parent::_initialize();
        $this->_user_id = I('request.user_id');
    }

    //废弃
    function get_list(){
        if(!$_POST['page'] || !$_POST['pagenum']){
            render('10004', '参数错误');
        }
        $cond['ecm_commission.user_id'] = $this->_user_id;
        if(I('request.start_time') && I('request.end_time')){
            $start_time = strtotime(I('request.start_time').'-01 00:00:00');
            $end_time_first = strtotime(I('request.end_time').'-01 00:00:00');
            $end_time = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m-d H:i:s',$end_time_first).' +1 month -1 day')));
            $cond['ecm_commission.finish_time'] = array(
                'between',array($start_time,$end_time)
            );
        }else{
            $start_time = strtotime(date('Y-m-d 00:00:00').' -7 day');
            $end_time = time();
            $cond['ecm_commission.finish_time'] = array(
                'between',array($start_time,$end_time)
            );
        }
        $res = M('commission')
            ->join('ecm_member on ecm_commission.user_id = ecm_member.user_id')
            ->field('ecm_commission.*,ecm_member.phone_mob')
            ->where($cond)
            ->order('finish_time desc')
            ->limit($_POST['pagenum'])
            ->page($_POST['page'])
            ->select();


        foreach ($res  as $k => $v){
            $res[$k]['finish_time'] = date("Y-m-d H:i:s",$v['finish_time']);
        }
        render('10000','查询成功',array('data'=>$res ? $res : array()));
    }

    //交易明细
    function get_log_list()
    {
        if (!$_POST['page'] || !$_POST['pagenum']) {
            render('10004', '参数错误');
        }
        $cond['ecm_commission_log.user_id'] = $this->_user_id;
        if(I('request.start_time') && I('request.end_time')){
            $start_time = strtotime(I('request.start_time').'-01 00:00:00');
            $end_time_first = strtotime(I('request.end_time').'-01 00:00:00');
            $end_time = strtotime(date('Y-m-d 23:59:59', strtotime(date('Y-m-d H:i:s',$end_time_first).' +1 month -1 day')));
            $cond['ecm_commission_log.finish_time'] = array(
              'between',array($start_time,$end_time)
            );
        }else{
//            $start_time = strtotime(date('Y-m-d 00:00:00').' -7 day');
//            $end_time = time();
//            $cond['ecm_commission_log.finish_time'] = array(
//                'between',array($start_time,$end_time)
//            );
        }
        $res = M('commission_log')
            ->join('ecm_member on ecm_commission_log.fans_id = ecm_member.user_id')
            ->field('ecm_commission_log.*,ecm_member.phone_mob')
            ->where($cond)
            ->order('finish_time desc')
            ->limit($_POST['pagenum'])
            ->page($_POST['page'])
            ->select();


        foreach ($res as $k => $v) {
            $res[$k]['finish_time'] = date("Y.m.d H:i", $v['finish_time']);
            $v['phone_mob'] ? $res[$k]['phone_mob'] = substr_replace($v['phone_mob'], '****', 3, 4) : '';
            switch ($v['status']){
                case 1:
                    $res[$k]['status'] = '未入账';
                    break;
                case 2:
                    $res[$k]['status'] = '已入账';
                    break;
                case 3:
                    $res[$k]['status'] = '已结算';
                    break;
            }

        }
        render('10000','查询成功',array('data'=>$res ? $res : array()));
    }

    //预估收益
    function get_expected_log_list()
    {
        if (!$_POST['page'] || !$_POST['pagenum']) {
            render('10004', '参数错误');
        }
        $cond['ecm_commission_log.user_id'] = $this->_user_id;
        //确定日子
        $last_month_time= strtotime(date("Y-m-d H:i:s", strtotime("-1 month")));
        $last_last_month_time= strtotime(date("Y-m-d H:i:s", strtotime("-2 month")));
        $y = date("Y",time());
        if($y <= 5){
            //上上个月时间(time)
            $start_time = strtotime(date('Y',$last_last_month_time).'-'.date('m',$last_last_month_time).'-21');
            $end_time = strtotime(date('Y',$last_month_time).'-'.date('m',$last_month_time).'-20');
        }else{
            //上个月时间(time)
            $start_time = strtotime(date('Y',$last_month_time).'-'.date('m',$last_month_time).'-21');
            $end_time = strtotime(date('Y',time()).'-'.date('m',time()).'-20');
        }

        $cond['ecm_commission_log.finish_time'] = array(
            'between',array($start_time,$end_time)
        );
//        }
        $res = M('commission_log')
            ->join('ecm_member on ecm_commission_log.fans_id = ecm_member.user_id')
            ->field('ecm_commission_log.*,ecm_member.phone_mob')
            ->where($cond)
            ->order('finish_time desc')
            ->limit($_POST['pagenum'])
            ->page($_POST['page'])
            ->select();


        foreach ($res as $k => $v) {
            $res[$k]['finish_time'] = date("Y.m.d H:i", $v['finish_time']);
            $v['phone_mob'] ? $res[$k]['phone_mob'] = substr_replace($v['phone_mob'], '****', 3, 4) : '';
            switch ($v['status']){
                case 1:
                    $res[$k]['status'] = '未入账';
                    break;
                case 2:
                    $res[$k]['status'] = '已入账';
                    break;
                case 3:
                    $res[$k]['status'] = '已结算';
                    break;
            }

        }
        render('10000','查询成功',array('data'=>$res ? $res : array()));
    }

    //我的粉丝
    function my_fans()
    {
        if (!$_POST['page'] || !$_POST['pagenum']) {
            render('10004', '参数错误');
        }
        $res = M('member')
            ->where(array('second_class' => $this->_user_id ,'fourth_class' => $this->_user_id))
            ->limit($_POST['pagenum'])
            ->order('reg_time desc')
            ->page($_POST['page'])
            ->select();
        foreach ($res as $k => $v){
            $v['user_name'] ? $res[$k]['user_name'] = substr_replace($v['user_name'], '****', 3, 4) : '';
            $v['phone_mob'] ? $res[$k]['phone_mob'] = substr_replace($v['phone_mob'], '****', 3, 4) : '';
            $v['reg_time'] ? $res[$k]['reg_time'] = date("Y.m.d H:i",$res[$k]['reg_time']) : '';
        }
        $start_time = strtotime(date("Y-m-d",time()));
        $end_time = $start_time+24 * 60 * 60-1;
        $res_new = M('member')
            ->where(array('second_class' => $this->_user_id ,'fourth_class' => $this->_user_id,'reg_time'=>array('between',array($start_time,$end_time))))
            ->count();
        $res_fans = M('member')
            ->where(array('second_class' => $this->_user_id ,'fourth_class' => $this->_user_id))
            ->count();
        render('10000','查询成功',array('data'=>$res ? $res : array(),'new'=>$res_new,'fans'=>$res_fans));
    }

    //我的推广
    function my_promote()
    {
        $res = M('member')
            ->where(array('second_class' => $this->_user_id ,'fourth_class' => $this->_user_id))
            ->limit($_POST['pagenum'])
            ->page($_POST['page'])
            ->select();
        foreach ($res as $k => $v){
            $v['user_name'] ? $res[$k]['user_name'] = substr_replace($v['user_name'], '****', 3, 4) : '';
            $v['phone_mob'] ? $res[$k]['phone_mob'] = substr_replace($v['phone_mob'], '****', 3, 4) : '';
        }
        $start_time = strtotime(date("Y-m-d",time()));
        $end_time = $start_time+24 * 60 * 60-1;
        //今日新增
        $res_new = M('member')
            ->where(array('second_class' => $this->_user_id ,'fourth_class' => $this->_user_id,'reg_time'=>array('between',array($start_time,$end_time))))
            ->count();
        //我的粉丝
        $res_fans = M('member')
            ->where(array('second_class' => $this->_user_id ,'fourth_class' => $this->_user_id))
            ->count();
//        //昨日收益
//
//        //昨日开始时间
//        $yesterday_start_time = strtotime(date("Y-m-d",strtotime("-1 day")));
//        //昨日结束时间
//        $yesterday_end_time = strtotime(date("Y-m-d 23:59:59",strtotime("-1 day")));
//        $res_yesterday_commission = M('commission_detail')
//            ->field('ifnull(sum(commission),0) as scommission')
//            ->where(array('order_time' => array('betweend',array($yesterday_start_time,$yesterday_end_time)), 'user_id' => $this->_user_id))
//            ->find();
        $res_all_commission = M('commission_detail')
            ->field('ifnull(sum(commission),0) as scommission')
            ->where(array('user_id' => $this->_user_id))
            ->find();
        //今日收益
        //今日开始时间
        $today_start_time = strtotime(date("Y-m-d",strtotime("-1 day")));
        //今日结束时间
        $today_end_time = strtotime(date("Y-m-d 23:59:59",strtotime("-1 day")));
        $res_today_commission = M('commission_detail')
            ->field('ifnull(sum(commission),0) as scommission')
            ->where(array('order_time' => array('betweend',array($today_start_time,$today_end_time)), 'user_id' => $this->_user_id))
            ->find();
        //图
        $pic = M('limited_setting')->find();
        //是否绑定
        $res_my_bank = M('bank_card')->where(array('user_id'=>$_POST['user_id']))->find();

        render('10000','查询成功',array('data'=> array('new'=>$res_new,'fans'=>$res_fans,'today_commission'=>$res_today_commission['scommission'],'all_commission'=>$res_all_commission['scommission'],'pic_url'=>C('SITE_URL').$pic['image_extension'],'promote_url'=>C('SITE_URL').'appserver/index.php?m=Home&c=Textarea&a=cash','text'=>'规则攻略','is_bind'=>$res_my_bank ? 1 : 0,'promotion_agreement_url'=>C('SITE_URL').'appserver/index.php?m=Home&c=Textarea&a=promotion','share_title'=>'好友送您100元现金优惠券,更多商品等您选购','share_pic'=>C('SITE_URL').$pic['promote_image'])));
    }

    //支付宝提现(暂弃)
    function add_wishdraw(){
        if(!I('request.user_name')){
            render('10004','请填写真实姓名');
        }
        if(!I('request.user_name')){
            render('10004','请填写真实姓名');
        }
        if(!I('request.number')){
            render('10004','请填写支付宝账号');
        }
        if(!I('request.money')){
            render('10004','请选择提现金额');
        }
        $res_user = M('member')->where(array('user_id'=>$this->_user_id))->find();
        if($res_user['commission_dj'] < (string)I('request.money')){
            render('10004','金额不足');
        }
        $data = array(
            'user_id' => $this->_user_id,
            'money' => I('request.money'),
            'type' => 2,
            'number' => I('request.number'),
            'user_name' => I('request.user_name'),
            'phone_mob' => $res_user['phone_mob'],
            'create_time' => time(),
            'sn' => date('YmdHis', time() + 8 * 3600) . rand(1000, 9999)
        );
        $res = M('withdraw')->add($data);
        if(!$res){
            render('10004','提现申请失败');
        }
        $res_user_save = M('member')->where(array('user_id'=>$this->_user_id))->save(array('commission'=>(float)$res_user['commission']-I('request.money'),'commission_dj'=>(float)$res_user['commission_dj']-I('request.money')));
        render('10000','提现申请成功');
    }

    //体现列表(暂弃)
    function get_wishdraw_list(){
        if (!$_POST['page'] || !$_POST['pagenum']) {
            render('10004', '参数错误');
        }
        $res = M('withdraw')
            ->where(array('user_id'=>$this->_user_id))
            ->limit($_POST['pagenum'])
            ->page($_POST['page'])
            ->select();

        foreach ($res as $k => $v){
            $res[$k]['create_time'] = date("Y-m-d H:i:s",$v['create_time']);
            if($v['status'] == 1 || $v['status'] == 2){
                $res[$k]['sign'] = '-';
                $res[$k]['remark'] = '提现至支付宝(已申请)';
            }else if($v['status'] == 3 || $v['status'] == 5){
                $res[$k]['sign'] = '+';
                $res[$k]['remark'] = '提现失败退回';
            }else if($v['status'] == 4){
                $res[$k]['sign'] = '-';
                $res[$k]['remark'] = '提现至支付宝(提现成功)';
            }
        }

        render('10000','提现申请成功',array('data'=>$res));
    }

    //支付宝授权(暂弃)
    public function aliauthorize(){
        $appid =  C('app_alipay_partner_id'); // 商户账号appid
        $sign_type = 'RSA2';
        $targetId = mt_rand(000000,999999);//此处随机获取
        $data = [
            'apiname'=>'com.alipay.account.auth',
            'method'=>'alipay.open.auth.sdk.code.get',
            'app_id'=>$appid,//支付宝分配给开发者的应用ID
            'app_name'=>'mc',
            'biz_type'=>'openservice',
            'pid'=>'2088531118503209',//签约的支付宝账号对应的支付宝唯一用户号，以2088开头的16位纯数字组成 登录你的支付宝 用户信息中 可以找到
            'product_id'=>'APP_FAST_LOGIN', //标识授权类型，取值范围：AUTHACCOUNT代表授权；LOGIN代表登录
            'scope'=>'kuaijie',
            'target_id'=>$targetId, //商户标识该次用户授权请求的ID，该值在商户端应保持唯一
            'auth_type'=>'AUTHACCOUNT',//授权类型  AUTHACCOUNT:授权 LOGIN:登录
            'sign_type'=>$sign_type,//签名算法类型
        ];
        //读取配置信息
        include_once BASE_PATH.'/appserver/ThinkPHP/Library/Mall/Payment/Alipay/aop/AopClient.php';
        $aop = new \AopClient;
        $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
        $aop->appId = $appid;//支付宝分配给开发者的应用ID
        $aop->rsaPrivateKey = C('app_alipay_private_key');//支付宝私钥
        $aop->format = "json";
        $aop->charset = "UTF-8";
        $aop->signType = "RSA2";
        $aop->alipayrsaPublicKey = C('app_alipay_public_key');//支付宝公钥
        $sign =  $aop->generateSign($data,$sign_type);//生成sing 此处用的 支付宝 demo封装好的
        $sign = urlencode($sign);
        ksort($data);
        $str='';
        foreach($data as $k=>$v) {
            $str.=$k.'='.$v.'&';
        }
        $str.= 'sign='.$sign;
        /* var_dump($str);
         exit;*/
//        $str.= 'sign='.$sign;
        /* var_dump($str);
         exit;*/
//        var_dump($str);exit;
        render('10000','提现申请成功',array('data'=>$str));;//返给前端 去做授权处理哦！
    }

    //设置支付宝id(暂弃)
    public function setAlipayUserId(){
        if(!$_POST['alipay_user_id'] || !$_POST['user_id']){
            render('10004','参数错误');
        }
        $res_save = M('member')->where(array('user_id'=>$_POST['user_id']))->save(array('alipay_user_id'=>$_POST['alipay_user_id']));
        render('10000','修改成功');
    }

    //设置银行卡号
    public function setBankCard(){
        if(!$_POST['user_id']){
            render('10004','参数错误');
        }
        $url = 'https://ccdcapi.alipay.com/validateAndCacheCardInfo.json?cardNo='.$_POST['bank_card'].'&cardBinCheck=true';
        $result = json_decode(request_get($url),true);
        if(!$result['validated']){
            render('10004','银行卡号错误');
        }
        $res_bank = M('bank')->where(array('code'=>$result['bank']))->find();
        if(!$res_bank){
            render('10004','银行卡号错误');
        }
        $res_my_bank = M('bank_card')->where(array('user_id'=>$_POST['user_id']))->find();
        if(!$res_my_bank){
            $data = array(
                'user_id' => $_POST['user_id'],
                'bank' => $res_bank['bank'],
                'open_bank' => $_POST['open_bank'],
                'bank_card' => $_POST['bank_card'],
                'name' => $_POST['name'],
                'phone_mob' => $_POST['phone_mob'],
                'user_no' => $_POST['user_no']
            );
            $res_add = M('bank_card')->add($data);
        }else{
            $data = array(
                'bank' => $res_bank['bank'],
                'open_bank' => $_POST['open_bank'],
                'bank_card' => $_POST['bank_card'],
                'name' => $_POST['name'],
                'phone_mob' => $_POST['phone_mob'],
                'user_no' => $_POST['user_no']
            );
            $res_save = M('bank_card')->where(array('user_id'=>$_POST['user_id']))->save($data);
        }

        render('10000','绑定成功');
    }

    //我的银行卡信息
    public function myBankCard(){
        if(!$_POST['user_id']){
            render('10004','参数错误');
        }
        $res_my_bank = M('bank_card')->where(array('user_id'=>$_POST['user_id']))->find();
        render('10000','查询成功',array('data'=>$res_my_bank ? $res_my_bank : (object)array()));
    }

    //
    function accountAndCommission($order_id){
        !$order_id ? $order_id = $_POST['order_id'] : $order_id;
        $res_order = M('order')->where(array('order_id'=>$order_id))->find();
        M('order')->startTrans();
        if(!$res_order){
            M('order')->rollback();
            return false;
        }
        $res_order_goods = M('order_goods')->where(array('order_id'=>$order_id))->find();
        M('order')->startTrans();
        if(!$res_order_goods){
            M('order')->rollback();
            return false;
        }
        $res_member = M('member')->where(array('user_id'=>$res_order['buyer_id']))->find();
        if(!$res_member){
            M('order')->rollback();
            return false;
        }
        //推荐人
        if($res_member['second_class']){
            $res_refer = M('member')->where(array('user_id'=>$res_member['second_class']))->find();
            if(!$res_refer){
                M('order')->rollback();
                return false;
            }
            //如果自己为推荐人把推荐人变为自己
            if($res_member['is_promoters'] == 1){
                $res_refer = $res_member;
            }
            //验证推荐人
            if($res_refer['is_promoters'] == 1 && $res_refer['second_class'] == $res_refer['user_id']){
                //取比例
                $res_config = M('mall_config')->where(array('code'=>'promotion_proportion'))->find();
                if(!$res_config['value']){
                    M('order')->rollback();
                    return false;
                }
                $commssion_amount = (float)$res_order_goods['price_amount']*(float)$res_config['value'];

                //存流水
                $res_member_save = M('member')->where(array('user_id'=>$res_refer['user_id']))->save(array('commission'=>(float)$res_refer['commission']+$commssion_amount));
                if(!$res_member_save){
                    M('order')->rollback();
                    return false;
                }
//                $res_order_save = M('order')->where(array('order_id'=>$res_order['order_id']))->save(array('is_change'=>1));
//                if(!$res_order_save){
//                    M('order')->rollback();
//                    return false;
//                }
                //存订单明细
                $data_commission = array(
                    'user_id' => $res_refer['user_id'],
                    'sign' => '+',
                    'commission_money' => $commssion_amount,
                    'finish_time' => time(),
                    'remark' => '佣金结算'
                );
                $res_commission = M('commission')->add($data_commission);
                if (!$res_commission){
                    M('order')->rollback();
                    return false;
                }
                //存佣金明细
                $data_commission_log = array(
                    'user_id' => $res_refer['user_id'],
                    'fans_id' => $res_member['user_id'],
                    'sign' => '+',
                    'order_id' => $res_order['order_id'],
                    'order_money' => $res_order_goods['price_amount'],
                    'commission_money' => $commssion_amount,
                    'finish_time' => time()
                );
                $res_commission_log = M('commission_log')->add($data_commission_log);
                if (!$res_commission_log){
                    M('order')->rollback();
                    return false;
                }

                //存入账detail
                $res_goods = M('goods')->where(array('goods_id'=>$res_order_goods['goods_id']))->find();
                $res_spec = M('goods_spec')->where(array('spec_id'=>$res_order_goods['spec_id']))->find();
                $res_store = M('store')->where(array('store_id'=>$res_refer['user_id']))->find();
                if(!$res_goods || !$res_spec || !$res_store){
                    M('order')->rollback();
                    return false;
                }
                $data_commission_detail = array(
                    'order_id' => $res_order['order_id'],
                    'user_id' => $res_refer['user_id'],
                    'order_sn' => $res_order['order_sn'],
                    'order_pay_time' => $res_order['pay_time'],
//                    'order_finish_time' => $res_order['finished_time'],
                    'goods_id' => $res_goods['goods_id'],
                    'spec_id' => $res_spec['spec_id'],
                    'goods_name' => $res_goods['goods_name'],
                    'sku' => $res_spec['sku'],
                    'price' => $res_order_goods['price_amount'],
                    'num' => 1,
                    'price_amount' => $res_order_goods['price_amount'],
                    'sign' => '+',
                    'commission_proportion' => $res_config['value'],
                    'commission' => (float)$res_order_goods['price_amount'] * (float)$res_config['value'],
                    'stock_style' => $res_spec['spec_3value'] == 25 ? '香港直邮' : '境内仓',
                    'user_name' => $res_refer['phone_mob'],
                    'serial_number' => $res_store['serial_number']

                );
                $res_commission_detail = M('commission_detail')->add($data_commission_detail);
                if (!$res_commission_detail){
                    M('order')->rollback();
                    return false;
                }
            }
        }


        M('order')->commit();
    }

//    function bank (){
//        $json = '{"CDB":"国家开发银行","ICBC":"中国工商银行","ABC":"中国农业银行","BOC":"中国银行","CCB":"中国建设银行","PSBC":"中国邮政储蓄银行","COMM":"交通银行","CMB":"招商银行","SPDB":"上海浦东发展银行","CIB":"兴业银行","HXBANK":"华夏银行","GDB":"广东发展银行","CMBC":"中国民生银行","CITIC":"中信银行","CEB":"中国光大银行","EGBANK":"恒丰银行","CZBANK":"浙商银行","BOHAIB":"渤海银行","SPABANK":"平安银行","SHRCB":"上海农村商业银行","YXCCB":"玉溪市商业银行","YDRCB":"尧都农商行","BJBANK":"北京银行","SHBANK":"上海银行","JSBANK":"江苏银行","HZCB":"杭州银行","NJCB":"南京银行","NBBANK":"宁波银行","HSBANK":"徽商银行","CSCB":"长沙银行","CDCB":"成都银行","CQBANK":"重庆银行","DLB":"大连银行","NCB":"南昌银行","FJHXBC":"福建海峡银行","HKB":"汉口银行","WZCB":"温州银行","QDCCB":"青岛银行","TZCB":"台州银行","JXBANK":"嘉兴银行","CSRCB":"常熟农村商业银行","NHB":"南海农村信用联社","CZRCB":"常州农村信用联社","H3CB":"内蒙古银行","SXCB":"绍兴银行","SDEB":"顺德农商银行","WJRCB":"吴江农商银行","ZBCB":"齐商银行","GYCB":"贵阳市商业银行","ZYCBANK":"遵义市商业银行","HZCCB":"湖州市商业银行","DAQINGB":"龙江银行","JINCHB":"晋城银行JCBANK","ZJTLCB":"浙江泰隆商业银行","GDRCC":"广东省农村信用社联合社","DRCBCL":"东莞农村商业银行","MTBANK":"浙江民泰商业银行","GCB":"广州银行","LYCB":"辽阳市商业银行","JSRCU":"江苏省农村信用联合社","LANGFB":"廊坊银行","CZCB":"浙江稠州商业银行","DYCB":"德阳商业银行","JZBANK":"晋中市商业银行","BOSZ":"苏州银行","GLBANK":"桂林银行","URMQCCB":"乌鲁木齐市商业银行","CDRCB":"成都农商银行","ZRCBANK":"张家港农村商业银行","BOD":"东莞银行","LSBANK":"莱商银行","BJRCB":"北京农村商业银行","TRCB":"天津农商银行","SRBANK":"上饶银行","FDB":"富滇银行","CRCBANK":"重庆农村商业银行","ASCB":"鞍山银行","NXBANK":"宁夏银行","BHB":"河北银行","HRXJB":"华融湘江银行","ZGCCB":"自贡市商业银行","YNRCC":"云南省农村信用社","JLBANK":"吉林银行","DYCCB":"东营市商业银行","KLB":"昆仑银行","ORBANK":"鄂尔多斯银行","XTB":"邢台银行","JSB":"晋商银行","TCCB":"天津银行","BOYK":"营口银行","JLRCU":"吉林农信","SDRCU":"山东农信","XABANK":"西安银行","HBRCU":"河北省农村信用社","NXRCU":"宁夏黄河农村商业银行","GZRCU":"贵州省农村信用社","FXCB":"阜新银行","HBHSBANK":"湖北银行黄石分行","ZJNX":"浙江省农村信用社联合社","XXBANK":"新乡银行","HBYCBANK":"湖北银行宜昌分行","LSCCB":"乐山市商业银行","TCRCB":"江苏太仓农村商业银行","BZMD":"驻马店银行","GZB":"赣州银行","WRCB":"无锡农村商业银行","BGB":"广西北部湾银行","GRCB":"广州农商银行","JRCB":"江苏江阴农村商业银行","BOP":"平顶山银行","TACCB":"泰安市商业银行","CGNB":"南充市商业银行","CCQTGB":"重庆三峡银行","XLBANK":"中山小榄村镇银行","HDBANK":"邯郸银行","KORLABANK":"库尔勒市商业银行","BOJZ":"锦州银行","QLBANK":"齐鲁银行","BOQH":"青海银行","YQCCB":"阳泉银行","SJBANK":"盛京银行","FSCB":"抚顺银行","ZZBANK":"郑州银行","SRCB":"深圳农村商业银行","BANKWF":"潍坊银行","JJBANK":"九江银行","JXRCU":"江西省农村信用","HNRCU":"河南省农村信用","GSRCU":"甘肃省农村信用","SCRCU":"四川省农村信用","GXRCU":"广西省农村信用","SXRCCU":"陕西信合","WHRCB":"武汉农村商业银行","YBCCB":"宜宾市商业银行","KSRB":"昆山农村商业银行","SZSBK":"石嘴山银行","HSBK":"衡水银行","XYBANK":"信阳银行","NBYZ":"鄞州银行","ZJKCCB":"张家口市商业银行","XCYH":"许昌银行","JNBANK":"济宁银行","CBKF":"开封市商业银行","WHCCB":"威海市商业银行","HBC":"湖北银行","BOCD":"承德银行","BODD":"丹东银行","JHBANK":"金华银行","BOCY":"朝阳银行","LSBC":"临商银行","BSB":"包商银行","LZYH":"兰州银行","BOZK":"周口银行","DZBANK":"德州银行","SCCB":"三门峡银行","AYCB":"安阳银行","ARCU":"安徽省农村信用社","HURCB":"湖北省农村信用社","HNRCC":"湖南省农村信用社","NYNB":"广东南粤银行","LYBANK":"洛阳银行","NHQS":"农信银清算中心","CBBQS":"城市商业银行资金清算中心"}';
//        $array = json_decode($json,true);
//        foreach ($array as $k=>$v) {
//            $new_array[] = array(
//                'code' => $k,
//                'bank' => $v
//            );
//        }
//        M('bank')->addAll($new_array);
//    }



}
